﻿@inherits BaseComponent

<CmsCard Class="cl-bbs-menu">
    <div style="margin-bottom:10px;">
        <AntButton Name="去提问" Block OnClick="@($"location='{Url.PostFormUrl}'")" />
    </div>
    <a href="@Url.UserCreatorUrl" class="@(IsActive("")?"active":"")">
        <i class="far fa-home" />
        <span style="margin-left:10px;">首页</span>
    </a>
    @foreach (var item in UserMenus.OrderBy(p => p.Sort))
    {
        <a href="@item.Url" class="@(IsActive(item.ActiveUrl)?"active":"")">
            <i class="@item.Icon" />
            <span style="margin-left:10px;">@item.Name</span>
        </a>
    }
</CmsCard>

@code {
    private List<UserMenuAttribute> UserMenus = [];

    protected override async Task OnInitAsync()
    {
        await base.OnInitAsync();
        UserMenus = AppConfig.GetUserMenus(CurrentUser);
    }

    private bool IsActive(string code)
    {
        var uri = Navigation.Uri.Split('?')[0];
        if (string.IsNullOrWhiteSpace(code))
            return uri.EndsWith("/creator");
        else
            return uri.Contains($"/creator/{code}");
    }
}